//
//  PaperListViewController.m
//  PeopleStreet
//
//  Created by 辰领科技 on 16/5/4.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "PaperListViewController.h"
#import "PaperListTableViewCell.h"
#import "ForSalePaperViewController.h"
static NSString *cellIdentify = @"PaperListTableViewCell";
@interface PaperListViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation PaperListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initViewLayout];
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self.tableView registerNib:[UINib nibWithNibName:cellIdentify bundle:nil] forCellReuseIdentifier:cellIdentify];
    _tableView.dataSource = self;
    _tableView.delegate = self;
}

- (IBAction)back:(id)sender {
    [self.navigationController  popViewControllerAnimated:YES];
}

#pragma mark -- UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 57*VerticalRatio();
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    PaperListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify ];
    if (cell==nil) {
        cell = [[PaperListTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentify];
        
    }
    for (UIView *view in cell.subviews) {
        if ([view isKindOfClass:[UILabel class]] ||[view isKindOfClass:[UIImageView class]]||[view isKindOfClass:[UIScrollView class]]||[view isKindOfClass:[UIButton class]]) {
            [view removeFromSuperview];
        }
    }
    NSDictionary * dic = _paperArray[indexPath.row];
    cell.paperTitle.text = [NSString stringWithFormat:@"%@",dic[@"mgprName"]];
    cell.paperPrice.text = [NSString stringWithFormat:@"¥%@ 门市价：¥%@",dic[@"mgpiGourponAmount"],dic[@"mgpiOrginalAmount"]];
    cell.paperSold.text = [NSString stringWithFormat:@"已售%@",dic[@"mgprSelledcount"]];
    
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _paperArray.count;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    ForSalePaperViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"ForSalePaper"];
    NSDictionary * dic = _paperArray[indexPath.row];
    page.groupShoppingId = dic[@"mgprId"];
    [self.navigationController   pushViewController:page animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
